home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / test / test_b2.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  11.4 KB  |  470 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. *
  5. print 'oct'
  6. if oct(100) != '0144':
  7.     raise TestFailed, 'oct(100)'
  8.  
  9. if oct(0x64L) != '0144L':
  10.     raise TestFailed, 'oct(100L)'
  11.  
  12. if oct(-100) not in ('037777777634', '01777777777777777777634'):
  13.     raise TestFailed, 'oct(-100)'
  14.  
  15. if oct(-0x64L) != '-0144L':
  16.     raise TestFailed, 'oct(-100L)'
  17.  
  18. print 'open'
  19. fp = open(TESTFN, 'w')
  20.  
  21. try:
  22.     fp.write('1+1\n')
  23.     fp.write('1+1\n')
  24.     fp.write('The quick brown fox jumps over the lazy dog')
  25.     fp.write('.\n')
  26.     fp.write('Dear John\n')
  27.     fp.write('XXX' * 100)
  28.     fp.write('YYY' * 100)
  29. finally:
  30.     fp.close()
  31.  
  32. fp = open(TESTFN, 'r')
  33.  
  34. try:
  35.     if fp.readline(4) != '1+1\n':
  36.         raise TestFailed, 'readline(4) # exact'
  37.     
  38.     if fp.readline(4) != '1+1\n':
  39.         raise TestFailed, 'readline(4) # exact'
  40.     
  41.     if fp.readline() != 'The quick brown fox jumps over the lazy dog.\n':
  42.         raise TestFailed, 'readline() # default'
  43.     
  44.     if fp.readline(4) != 'Dear':
  45.         raise TestFailed, 'readline(4) # short'
  46.     
  47.     if fp.readline(100) != ' John\n':
  48.         raise TestFailed, 'readline(100)'
  49.     
  50.     if fp.read(300) != 'XXX' * 100:
  51.         raise TestFailed, 'read(300)'
  52.     
  53.     if fp.read(1000) != 'YYY' * 100:
  54.         raise TestFailed, 'read(1000) # truncate'
  55. finally:
  56.     fp.close()
  57.  
  58. print 'ord'
  59. if ord(' ') != 32:
  60.     raise TestFailed, "ord(' ')"
  61.  
  62. if ord('A') != 65:
  63.     raise TestFailed, "ord('A')"
  64.  
  65. if ord('a') != 97:
  66.     raise TestFailed, "ord('a')"
  67.  
  68. print 'pow'
  69. if pow(0, 0) != 1:
  70.     raise TestFailed, 'pow(0,0)'
  71.  
  72. if pow(0, 1) != 0:
  73.     raise TestFailed, 'pow(0,1)'
  74.  
  75. if pow(1, 0) != 1:
  76.     raise TestFailed, 'pow(1,0)'
  77.  
  78. if pow(1, 1) != 1:
  79.     raise TestFailed, 'pow(1,1)'
  80.  
  81. if pow(2, 0) != 1:
  82.     raise TestFailed, 'pow(2,0)'
  83.  
  84. if pow(2, 10) != 1024:
  85.     raise TestFailed, 'pow(2,10)'
  86.  
  87. if pow(2, 20) != 1024 * 1024:
  88.     raise TestFailed, 'pow(2,20)'
  89.  
  90. if pow(2, 30) != 1024 * 1024 * 1024:
  91.     raise TestFailed, 'pow(2,30)'
  92.  
  93. if pow(-2, 0) != 1:
  94.     raise TestFailed, 'pow(-2,0)'
  95.  
  96. if pow(-2, 1) != -2:
  97.     raise TestFailed, 'pow(-2,1)'
  98.  
  99. if pow(-2, 2) != 4:
  100.     raise TestFailed, 'pow(-2,2)'
  101.  
  102. if pow(-2, 3) != -8:
  103.     raise TestFailed, 'pow(-2,3)'
  104.  
  105. if pow(0x0L, 0) != 1:
  106.     raise TestFailed, 'pow(0L,0)'
  107.  
  108. if pow(0x0L, 1) != 0:
  109.     raise TestFailed, 'pow(0L,1)'
  110.  
  111. if pow(0x1L, 0) != 1:
  112.     raise TestFailed, 'pow(1L,0)'
  113.  
  114. if pow(0x1L, 1) != 1:
  115.     raise TestFailed, 'pow(1L,1)'
  116.  
  117. if pow(0x2L, 0) != 1:
  118.     raise TestFailed, 'pow(2L,0)'
  119.  
  120. if pow(0x2L, 10) != 1024:
  121.     raise TestFailed, 'pow(2L,10)'
  122.  
  123. if pow(0x2L, 20) != 1024 * 1024:
  124.     raise TestFailed, 'pow(2L,20)'
  125.  
  126. if pow(0x2L, 30) != 1024 * 1024 * 1024:
  127.     raise TestFailed, 'pow(2L,30)'
  128.  
  129. if pow(-0x2L, 0) != 1:
  130.     raise TestFailed, 'pow(-2L,0)'
  131.  
  132. if pow(-0x2L, 1) != -2:
  133.     raise TestFailed, 'pow(-2L,1)'
  134.  
  135. if pow(-0x2L, 2) != 4:
  136.     raise TestFailed, 'pow(-2L,2)'
  137.  
  138. if pow(-0x2L, 3) != -8:
  139.     raise TestFailed, 'pow(-2L,3)'
  140.  
  141. if fcmp(pow(0.0, 0), 1.0):
  142.     raise TestFailed, 'pow(0.,0)'
  143.  
  144. if fcmp(pow(0.0, 1), 0.0):
  145.     raise TestFailed, 'pow(0.,1)'
  146.  
  147. if fcmp(pow(1.0, 0), 1.0):
  148.     raise TestFailed, 'pow(1.,0)'
  149.  
  150. if fcmp(pow(1.0, 1), 1.0):
  151.     raise TestFailed, 'pow(1.,1)'
  152.  
  153. if fcmp(pow(2.0, 0), 1.0):
  154.     raise TestFailed, 'pow(2.,0)'
  155.  
  156. if fcmp(pow(2.0, 10), 1024.0):
  157.     raise TestFailed, 'pow(2.,10)'
  158.  
  159. if fcmp(pow(2.0, 20), 1024.0 * 1024.0):
  160.     raise TestFailed, 'pow(2.,20)'
  161.  
  162. if fcmp(pow(2.0, 30), 1024.0 * 1024.0 * 1024.0):
  163.     raise TestFailed, 'pow(2.,30)'
  164.  
  165. for x in (2, 0x2L, 2.0):
  166.     for y in (10, 0xAL, 10.0):
  167.         for z in (1000, 0x3E8L, 1000.0):
  168.             pass
  169.         
  170.     
  171.  
  172. print 'range'
  173. if range(1, 5) != [
  174.     1,
  175.     2,
  176.     3,
  177.     4]:
  178.     raise TestFailed, 'range(1, 5)'
  179.  
  180. if range(0) != []:
  181.     raise TestFailed, 'range(0)'
  182.  
  183. if range(-3) != []:
  184.     raise TestFailed, 'range(-3)'
  185.  
  186. if range(1, 10, 3) != [
  187.     1,
  188.     4,
  189.     7]:
  190.     raise TestFailed, 'range(1, 10, 3)'
  191.  
  192. if range(5, -5, -3) != [
  193.     5,
  194.     2,
  195.     -1,
  196.     -4]:
  197.     raise TestFailed, 'range(5, -5, -3)'
  198.  
  199. print 'input and raw_input'
  200. import sys
  201. fp = open(TESTFN, 'r')
  202. savestdin = sys.stdin
  203.  
  204. try:
  205.     sys.stdin = fp
  206.     if input() != 2:
  207.         raise TestFailed, 'input()'
  208.     
  209.     if input('testing\n') != 2:
  210.         raise TestFailed, 'input()'
  211.     
  212.     if raw_input() != 'The quick brown fox jumps over the lazy dog.':
  213.         raise TestFailed, 'raw_input()'
  214.     
  215.     if raw_input('testing\n') != 'Dear John':
  216.         raise TestFailed, "raw_input('testing\\n')"
  217. finally:
  218.     sys.stdin = savestdin
  219.     fp.close()
  220.  
  221. print 'reduce'
  222. if reduce((lambda x, y: x + y), [
  223.     'a',
  224.     'b',
  225.     'c'], '') != 'abc':
  226.     raise TestFailed, 'reduce(): implode a string'
  227.  
  228. if reduce((lambda x, y: x + y), [
  229.     [
  230.         'a',
  231.         'c'],
  232.     [],
  233.     [
  234.         'd',
  235.         'w']], []) != [
  236.     'a',
  237.     'c',
  238.     'd',
  239.     'w']:
  240.     raise TestFailed, 'reduce(): append'
  241.  
  242. if reduce((lambda x, y: x * y), range(2, 8), 1) != 5040:
  243.     raise TestFailed, 'reduce(): compute 7!'
  244.  
  245. if reduce((lambda x, y: x * y), range(2, 21), 0x1L) != 0x21C3677C82B40000L:
  246.     raise TestFailed, 'reduce(): compute 20!, use long'
  247.  
  248.  
  249. class Squares:
  250.     
  251.     def __init__(self, max):
  252.         self.max = max
  253.         self.sofar = []
  254.  
  255.     
  256.     def __len__(self):
  257.         return len(self.sofar)
  258.  
  259.     
  260.     def __getitem__(self, i):
  261.         if not None if i <= i else i < self.max:
  262.             raise IndexError
  263.         
  264.         n = len(self.sofar)
  265.         while n <= i:
  266.             self.sofar.append(n * n)
  267.             n = n + 1
  268.         return self.sofar[i]
  269.  
  270.  
  271. if reduce((lambda x, y: x + y), Squares(10)) != 285:
  272.     raise TestFailed, 'reduce(<+>, Squares(10))'
  273.  
  274. if reduce((lambda x, y: x + y), Squares(10), 0) != 285:
  275.     raise TestFailed, 'reduce(<+>, Squares(10), 0)'
  276.  
  277. if reduce((lambda x, y: x + y), Squares(0), 0) != 0:
  278.     raise TestFailed, 'reduce(<+>, Squares(0), 0)'
  279.  
  280. print 'reload'
  281. import marshal
  282. reload(marshal)
  283. import string
  284. reload(string)
  285. print 'repr'
  286. if repr('') != "''":
  287.     raise TestFailed, "repr('')"
  288.  
  289. if repr(0) != '0':
  290.     raise TestFailed, 'repr(0)'
  291.  
  292. if repr(0x0L) != '0L':
  293.     raise TestFailed, 'repr(0L)'
  294.  
  295. if repr(()) != '()':
  296.     raise TestFailed, 'repr(())'
  297.  
  298. if repr([]) != '[]':
  299.     raise TestFailed, 'repr([])'
  300.  
  301. if repr({ }) != '{}':
  302.     raise TestFailed, 'repr({})'
  303.  
  304. print 'round'
  305. if round(0.0) != 0.0:
  306.     raise TestFailed, 'round(0.0)'
  307.  
  308. if round(1.0) != 1.0:
  309.     raise TestFailed, 'round(1.0)'
  310.  
  311. if round(10.0) != 10.0:
  312.     raise TestFailed, 'round(10.0)'
  313.  
  314. if round(1000000000.0) != 1000000000.0:
  315.     raise TestFailed, 'round(1000000000.0)'
  316.  
  317. if round(1e+20) != 1e+20:
  318.     raise TestFailed, 'round(1e20)'
  319.  
  320. if round(-1.0) != -1.0:
  321.     raise TestFailed, 'round(-1.0)'
  322.  
  323. if round(-10.0) != -10.0:
  324.     raise TestFailed, 'round(-10.0)'
  325.  
  326. if round(-1000000000.0) != -1000000000.0:
  327.     raise TestFailed, 'round(-1000000000.0)'
  328.  
  329. if round(-1e+20) != -1e+20:
  330.     raise TestFailed, 'round(-1e20)'
  331.  
  332. if round(0.1) != 0.0:
  333.     raise TestFailed, 'round(0.0)'
  334.  
  335. if round(1.1) != 1.0:
  336.     raise TestFailed, 'round(1.0)'
  337.  
  338. if round(10.1) != 10.0:
  339.     raise TestFailed, 'round(10.0)'
  340.  
  341. if round(1000000000.1) != 1000000000.0:
  342.     raise TestFailed, 'round(1000000000.0)'
  343.  
  344. if round(-1.1) != -1.0:
  345.     raise TestFailed, 'round(-1.0)'
  346.  
  347. if round(-10.1) != -10.0:
  348.     raise TestFailed, 'round(-10.0)'
  349.  
  350. if round(-1000000000.1) != -1000000000.0:
  351.     raise TestFailed, 'round(-1000000000.0)'
  352.  
  353. if round(0.9) != 1.0:
  354.     raise TestFailed, 'round(0.9)'
  355.  
  356. if round(9.9) != 10.0:
  357.     raise TestFailed, 'round(9.9)'
  358.  
  359. if round(999999999.9) != 1000000000.0:
  360.     raise TestFailed, 'round(999999999.9)'
  361.  
  362. if round(-0.9) != -1.0:
  363.     raise TestFailed, 'round(-0.9)'
  364.  
  365. if round(-9.9) != -10.0:
  366.     raise TestFailed, 'round(-9.9)'
  367.  
  368. if round(-999999999.9) != -1000000000.0:
  369.     raise TestFailed, 'round(-999999999.9)'
  370.  
  371. print 'setattr'
  372. import sys
  373. setattr(sys, 'spam', 1)
  374. if sys.spam != 1:
  375.     raise TestFailed, "setattr(sys, 'spam', 1)"
  376.  
  377. print 'str'
  378. if str('') != '':
  379.     raise TestFailed, "str('')"
  380.  
  381. if str(0) != '0':
  382.     raise TestFailed, 'str(0)'
  383.  
  384. if str(0x0L) != '0L':
  385.     raise TestFailed, 'str(0L)'
  386.  
  387. if str(()) != '()':
  388.     raise TestFailed, 'str(())'
  389.  
  390. if str([]) != '[]':
  391.     raise TestFailed, 'str([])'
  392.  
  393. if str({ }) != '{}':
  394.     raise TestFailed, 'str({})'
  395.  
  396. print 'tuple'
  397. if tuple(()) != ():
  398.     raise TestFailed, 'tuple(())'
  399.  
  400. if tuple((0, 1, 2, 3)) != (0, 1, 2, 3):
  401.     raise TestFailed, 'tuple((0, 1, 2, 3))'
  402.  
  403. if tuple([]) != ():
  404.     raise TestFailed, 'tuple([])'
  405.  
  406. if tuple([
  407.     0,
  408.     1,
  409.     2,
  410.     3]) != (0, 1, 2, 3):
  411.     raise TestFailed, 'tuple([0, 1, 2, 3])'
  412.  
  413. if tuple('') != ():
  414.     raise TestFailed, 'tuple()'
  415.  
  416. if tuple('spam') != ('s', 'p', 'a', 'm'):
  417.     raise TestFailed, "tuple('spam')"
  418.  
  419. print 'type'
  420. if type('') != type('123') or type('') == type(()):
  421.     raise TestFailed, 'type()'
  422.  
  423. print 'vars'
  424. a = b = None
  425. a = vars().keys()
  426. b = dir()
  427. a.sort()
  428. b.sort()
  429. if a != b:
  430.     raise TestFailed, 'vars()'
  431.  
  432. import sys
  433. a = vars(sys).keys()
  434. b = dir(sys)
  435. a.sort()
  436. b.sort()
  437. if a != b:
  438.     raise TestFailed, 'vars(sys)'
  439.  
  440.  
  441. def f0():
  442.     if vars() != { }:
  443.         raise TestFailed, 'vars() in f0()'
  444.     
  445.  
  446. f0()
  447.  
  448. def f2():
  449.     f0()
  450.     a = 1
  451.     b = 2
  452.     if vars() != {
  453.         'a': a,
  454.         'b': b }:
  455.         raise TestFailed, 'vars() in f2()'
  456.     
  457.  
  458. f2()
  459. print 'xrange'
  460. if tuple(xrange(10)) != tuple(range(10)):
  461.     raise TestFailed, 'xrange(10)'
  462.  
  463. if tuple(xrange(5, 10)) != tuple(range(5, 10)):
  464.     raise TestFailed, 'xrange(5,10)'
  465.  
  466. if tuple(xrange(0, 10, 2)) != tuple(range(0, 10, 2)):
  467.     raise TestFailed, 'xrange(0,10,2)'
  468.  
  469. unlink(TESTFN)
  470.